/**
 * @program: LeetCode
 * @description: LeetCode : 922. 按奇偶排序数组 II
 * @author: WXY
 * @create: 2023-02-08 10:26
 * @Version 1.0
 **/
public class Num922_sortArrayByParityII {
    public static int[] sortArrayByParityII(int[] nums) {
        int[] ans = new int[nums.length];
        int evenIndex = 0;
        int oddIndex = 1;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] % 2 == 0) {
                ans[evenIndex] = nums[i];
                evenIndex += 2;
            } else {
                ans[oddIndex] = nums[i];
                oddIndex += 2;
            }
        }
        return ans;
    }
}
